﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Common;
using System.IO;

public partial class Admin_FileDownLoad_Zrnet_upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["state"] != null)
        {
            string state = Request.QueryString["state"].ToString();
            switch (state.Trim())
            {
                case "up":
                    upLoad();
                    break;
                case "upLoad":
                    upResource();
                    break;
                default:
                    break;
            }
        }
    }
    #region 无水印,直接上传
    public void upLoad()
    {
        try
        {     
            int iTotal = Request.Files.Count;
            HttpPostedFile file = Request.Files[0];
            if (file.ContentLength == 0)
            {
                Response.Write("<table><tr><td bgcolor=#E9F5F5>还没选择图片　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
                return;
            }
            DotUpload up = new DotUpload();
            up.AllowFileExtens = "gif|jpg|bmp|png|pdf|rar|html|swf";
            string path = IOUtil.CreateDateTimeDir(Session["FCKeditor:UserFilesPath"].ToString().Trim()); 

            up.FilePath = path;
            up.MaxFileSize = 5000;
            if (up.DoUpload(file, "zR"))
            {
                string FullPath = up.ResultFileName;
                Response.Write("<script   language='javascript'>window.parent.document.getElementById('content').value='" + FullPath + "';");
                Response.Write("</script>");
                Response.Write("<table><tr><td bgcolor=#E9F5F5>上传成功　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");                    
            }
            else
            {
                Response.Write("<table><tr><td bgcolor=#E9F5F5>错误,需图片 大小500K以下　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
            }
                          
        }
        catch
        {
            Response.Write("<table><tr><td bgcolor=#E9F5F5>错误,需图片 大小500K以下　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
        }
    }
    #endregion

    #region 上传资源
    public void upResource() 
    {
        try
        {
            int iTotal = Request.Files.Count;
            HttpPostedFile file = Request.Files[0];
            if (file.ContentLength == 0)
            {
                Response.Write("<table><tr><td bgcolor=#E9F5F5>还没选择文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
                return;
            }
            DotUpload up = new DotUpload();
            up.AllowFileExtens = "pdf|rar|html|doc|swf";
            string path = IOUtil.CreateDateTimeDir("~/UploadFiles/CompanyProduct");

            up.FilePath = path;
            up.MaxFileSize = 2000;
            if (up.DoUpload(file, "zR"))
            {
                string FullPath = up.ResultFileName;

                Response.Write("<script   language='javascript'>window.parent.document.getElementById('content').value='" + FullPath + "';");
                Response.Write("</script>");
                Response.Write("<table><tr><td bgcolor=#E9F5F5>上传成功　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
            }
            else
            {
                Response.Write("<table><tr><td bgcolor=#E9F5F5>错误,需文件 大小500k以下　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
            }
        }
        catch
        {
            Response.Write("<table><tr><td bgcolor=#E9F5F5>错误,需文件 大小500k以下　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>");
        }
    }
    #endregion
}
